home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / include / net / RCS / if.h,v < prev    next >
Encoding:
Text File  |  1990-02-16  |  8.1 KB  |  285 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     90.02.16.14.04.07;  author rab;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.06.29.15.14.18;  author ouster;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.06.21.16.56.35;  author ouster;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @Added `struct ifdevea'.  It is used by the verilog program.
  32. @
  33. text
  34. @/*
  35.  * Copyright (c) 1982, 1986 Regents of the University of California.
  36.  * All rights reserved.
  37.  *
  38.  * Redistribution and use in source and binary forms are permitted
  39.  * provided that this notice is preserved and that due credit is given
  40.  * to the University of California at Berkeley. The name of the University
  41.  * may not be used to endorse or promote products derived from this
  42.  * software without specific prior written permission. This software
  43.  * is provided ``as is'' without express or implied warranty.
  44.  *
  45.  *    @@(#)if.h    7.2 (Berkeley) 12/30/87
  46.  */
  47.  
  48. #ifndef _IF
  49. #define _IF
  50.  
  51. /*
  52.  * Structures defining a network interface, providing a packet
  53.  * transport mechanism (ala level 0 of the PUP protocols).
  54.  *
  55.  * Each interface accepts output datagrams of a specified maximum
  56.  * length, and provides higher level routines with input datagrams
  57.  * received from its medium.
  58.  *
  59.  * Output occurs when the routine if_output is called, with three parameters:
  60.  *    (*ifp->if_output)(ifp, m, dst)
  61.  * Here m is the mbuf chain to be sent and dst is the destination address.
  62.  * The output routine encapsulates the supplied datagram if necessary,
  63.  * and then transmits it on its medium.
  64.  *
  65.  * On input, each interface unwraps the data received by it, and either
  66.  * places it on the input queue of a internetwork datagram routine
  67.  * and posts the associated software interrupt, or passes the datagram to a raw
  68.  * packet input routine.
  69.  *
  70.  * Routines exist for locating interfaces by their addresses
  71.  * or for locating a interface on a certain network, as well as more general
  72.  * routing and gateway routines maintaining information used to locate
  73.  * interfaces.  These routines live in the files if.c and route.c
  74.  */
  75.  
  76. /*
  77.  * Structure defining a queue for a network interface.
  78.  *
  79.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  80.  */
  81. struct ifnet {
  82.     char    *if_name;        /* name, e.g. ``en'' or ``lo'' */
  83.     short    if_unit;        /* sub-unit for lower level driver */
  84.     short    if_mtu;            /* maximum transmission unit */
  85.     short    if_flags;        /* up/down, broadcast, etc. */
  86.     short    if_timer;        /* time 'til if_watchdog called */
  87.     int    if_metric;        /* routing metric (external only) */
  88.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  89.     struct    ifqueue {
  90.         struct    mbuf *ifq_head;
  91.         struct    mbuf *ifq_tail;
  92.         int    ifq_len;
  93.         int    ifq_maxlen;
  94.         int    ifq_drops;
  95.     } if_snd;            /* output queue */
  96. /* procedure handles */
  97.     int    (*if_init)();        /* init routine */
  98.     int    (*if_output)();        /* output routine */
  99.     int    (*if_ioctl)();        /* ioctl routine */
  100.     int    (*if_reset)();        /* bus reset routine */
  101.     int    (*if_watchdog)();    /* timer routine */
  102. /* generic interface statistics */
  103.     int    if_ipackets;        /* packets received on interface */
  104.     int    if_ierrors;        /* input errors on interface */
  105.     int    if_opackets;        /* packets sent on interface */
  106.     int    if_oerrors;        /* output errors on interface */
  107.     int    if_collisions;        /* collisions on csma interfaces */
  108. /* end statistics */
  109.     struct    ifnet *if_next;
  110. };
  111.  
  112. #define    IFF_UP        0x1        /* interface is up */
  113. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  114. #define    IFF_DEBUG    0x4        /* turn on debugging */
  115. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  116. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  117. #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  118. #define    IFF_RUNNING    0x40        /* resources allocated */
  119. #define    IFF_NOARP    0x80        /* no address resolution protocol */
  120. /* next two not supported now, but reserved: */
  121. #define    IFF_PROMISC    0x100        /* receive all packets */
  122. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  123. /* flags set internally only: */
  124. #define    IFF_CANTCHANGE    (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  125.  
  126. /*
  127.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  128.  * input routines have queues of messages stored on ifqueue structures
  129.  * (defined above).  Entries are added to and deleted from these structures
  130.  * by these macros, which should be called with ipl raised to splimp().
  131.  */
  132. #define    IF_QFULL(ifq)        ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  133. #define    IF_DROP(ifq)        ((ifq)->ifq_drops++)
  134. #define    IF_ENQUEUE(ifq, m) { \
  135.     (m)->m_act = 0; \
  136.     if ((ifq)->ifq_tail == 0) \
  137.         (ifq)->ifq_head = m; \
  138.     else \
  139.         (ifq)->ifq_tail->m_act = m; \
  140.     (ifq)->ifq_tail = m; \
  141.     (ifq)->ifq_len++; \
  142. }
  143. #define    IF_PREPEND(ifq, m) { \
  144.     (m)->m_act = (ifq)->ifq_head; \
  145.     if ((ifq)->ifq_tail == 0) \
  146.         (ifq)->ifq_tail = (m); \
  147.     (ifq)->ifq_head = (m); \
  148.     (ifq)->ifq_len++; \
  149. }
  150. /*
  151.  * Packets destined for level-1 protocol input routines
  152.  * have a pointer to the receiving interface prepended to the data.
  153.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  154.  * IF_ADJ should be used otherwise to adjust for its presence.
  155.  */
  156. #define    IF_ADJ(m) { \
  157.     (m)->m_off += sizeof(struct ifnet *); \
  158.     (m)->m_len -= sizeof(struct ifnet *); \
  159.     if ((m)->m_len == 0) { \
  160.         struct mbuf *n; \
  161.         MFREE((m), n); \
  162.         (m) = n; \
  163.     } \
  164. }
  165. #define    IF_DEQUEUEIF(ifq, m, ifp) { \
  166.     (m) = (ifq)->ifq_head; \
  167.     if (m) { \
  168.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  169.             (ifq)->ifq_tail = 0; \
  170.         (m)->m_act = 0; \
  171.         (ifq)->ifq_len--; \
  172.         (ifp) = *(mtod((m), struct ifnet **)); \
  173.         IF_ADJ(m); \
  174.     } \
  175. }
  176. #define    IF_DEQUEUE(ifq, m) { \
  177.     (m) = (ifq)->ifq_head; \
  178.     if (m) { \
  179.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  180.             (ifq)->ifq_tail = 0; \
  181.         (m)->m_act = 0; \
  182.         (ifq)->ifq_len--; \
  183.     } \
  184. }
  185.  
  186. #define    IFQ_MAXLEN    50
  187. #define    IFNET_SLOWHZ    1        /* granularity is 1 second */
  188.  
  189. /*
  190.  * The ifaddr structure contains information about one address
  191.  * of an interface.  They are maintained by the different address families,
  192.  * are allocated and attached when an address is set, and are linked
  193.  * together so all addresses for an interface can be located.
  194.  */
  195. struct ifaddr {
  196.     struct    sockaddr ifa_addr;    /* address of interface */
  197.     union {
  198.         struct    sockaddr ifu_broadaddr;
  199.         struct    sockaddr ifu_dstaddr;
  200.     } ifa_ifu;
  201. #define    ifa_broadaddr    ifa_ifu.ifu_broadaddr    /* broadcast address */
  202. #define    ifa_dstaddr    ifa_ifu.ifu_dstaddr    /* other end of p-to-p link */
  203.     struct    ifnet *ifa_ifp;        /* back-pointer to interface */
  204.     struct    ifaddr *ifa_next;    /* next address for interface */
  205. };
  206.  
  207. /*
  208.  * Interface request structure used for socket
  209.  * ioctl's.  All interface ioctl's must have parameter
  210.  * definitions which begin with ifr_name.  The
  211.  * remainder may be interface specific.
  212.  */
  213. struct    ifreq {
  214. #define    IFNAMSIZ    16
  215.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  216.     union {
  217.         struct    sockaddr ifru_addr;
  218.         struct    sockaddr ifru_dstaddr;
  219.         struct    sockaddr ifru_broadaddr;
  220.         short    ifru_flags;
  221.         int    ifru_metric;
  222.         caddr_t    ifru_data;
  223.     } ifr_ifru;
  224. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  225. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  226. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  227. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  228. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  229. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  230. };
  231.  
  232. struct ifdevea {
  233.         char    ifr_name[IFNAMSIZ];
  234.         u_char default_pa[6];
  235.         u_char current_pa[6];
  236. }; 
  237.  
  238. /*
  239.  * Structure used in SIOCGIFCONF request.
  240.  * Used to retrieve interface configuration
  241.  * for machine (useful for programs which
  242.  * must know all networks accessible).
  243.  */
  244. struct    ifconf {
  245.     int    ifc_len;        /* size of associated buffer */
  246.     union {
  247.         caddr_t    ifcu_buf;
  248.         struct    ifreq *ifcu_req;
  249.     } ifc_ifcu;
  250. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  251. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  252. };
  253.  
  254. #ifdef KERNEL
  255. #include "../net/if_arp.h"
  256. struct    ifqueue rawintrq;        /* raw packet input queue */
  257. struct    ifnet *ifnet;
  258. struct    ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
  259. struct    ifaddr *ifa_ifwithdstaddr();
  260. #else KERNEL
  261. #include <net/if_arp.h>
  262. #endif KERNEL
  263.  
  264. #endif _IF
  265. @
  266.  
  267.  
  268. 1.2
  269. log
  270. @Add ifdefs so files won't be processed twice.
  271. @
  272. text
  273. @d199 6
  274. @
  275.  
  276.  
  277. 1.1
  278. log
  279. @Initial revision
  280. @
  281. text
  282. @d15 3
  283. d224 2
  284. @
  285.